<?php
namespace models\repositories;
use Doctrine\ORM\EntityRepository;
use entities;
class JenisProsedurRepository extends EntityRepository {

	/**
     * @inheritdoc
     */
    public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
    {
        $orderBy = $orderBy === null ? array('id' => 'desc') : $orderBy;
        return parent::findBy($criteria, $orderBy, $limit, $offset);
    }
	
	public function findAll($orderBy=null){		
		return $this->findBy(array(), $orderBy);
	}
	
	public function findByUserProfiles($userProfiles){
		$rsm = new \Doctrine\ORM\Query\ResultSetMapping;
		$rsm->addEntityResult('models\entities\JenisProsedur', 'u');
		$rsm->addFieldResult('u', 'id', 'id');
		$rsm->addFieldResult('u', 'nama', 'nama');
		$arr= array();
		foreach ($userProfiles as $obj) {
			$arr[] = $obj->getProfile()->getId();
		}
		$profiles = implode(",", $arr);
		
		$query = $this->_em->createNativeQuery("select jenis_prosedur.* from jenis_prosedur 
													inner join procedure_step on jenis_prosedur.id = procedure_step.type
													inner join profile ON procedure_step.profile = profile.id
													inner join user_profile on profile.id = user_profile.id
													where user_profile.profile_id in (".$profiles.");",$rsm);
		$str = $query->getResult();		
		
		echo "<pre>";print_r($str);die();
		return $str;	
									
	}
}

